package com.yanftch.stopcoding.common.util;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.WindowManager;

import java.awt.*;

public class SizeUtils {

    public static int getIdeaWidth(Project project) {
        Dimension dimension = getIdeaDimensions(project);
        return dimension.width;
    }

    public static int getIdeaHeight(Project project) {
        Dimension dimension = getIdeaDimensions(project);
        return dimension.height;
    }

    /**
    * 获取当前IDE的宽高
    */
    private static Dimension getIdeaDimensions(Project project) {
        // 获取当前的 IDE 主窗口
        Frame frame = WindowManager.getInstance().getFrame(project);
        if (frame != null) {
            // 获取窗口的宽度和高度
            int width = frame.getWidth();
            int height = frame.getHeight();
            return new Dimension(width, height);
        } else {
            return getScreenDimensions();
        }
    }

    public static int getScreenWidth() {
        Dimension screenSize = getScreenDimensions();
        return screenSize.width;
    }

    public static int getScreenHeight() {
        Dimension screenSize = getScreenDimensions();
        return screenSize.height;
    }

    private static Dimension getScreenDimensions() {
        // 使用 Toolkit 获取屏幕尺寸
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int width = screenSize.width;
        int height = screenSize.height;
        return screenSize;
    }
}
